Back to Editorials CodeCraft β
  • Github
  • Instagram
< >

Keypad Count

TIME LIMIT = 1 SEC.

  • Okay, this problem has no story. A straightforward problem for your reading pleasure. Given N phone numbers, count the number of times each key has to be pressed to obtain each phone number.
Input Output
The first line will contain N - the number of phone numbers.
The following N lines will contain the N different phone numbers.
Ten space-separated integers, indicating the number of times each key from 0−9 was pressed for every phone number on a new line.
Constraints
  • 1 ≤ N ≤ 100
  • 0000000000 ≤ Phone Number ≤ 9999999999
Example Test Case
Input             Output
10
1508748728
8311124221
7960991616
2249409666
7385194952
3726036749
8963370335
6800221139
9407430513
4794136898

1 1 1 0 1 1 0 2 3 0
0 4 3 1 1 0 0 0 1 0
1 2 0 0 0 0 3 1 0 3
1 0 2 0 2 0 3 0 0 2
0 1 1 1 1 2 0 1 1 2
1 0 1 2 1 0 2 2 0 1
1 0 0 4 0 1 1 1 1 1
2 2 2 1 0 0 1 0 1 1
2 1 0 2 2 1 0 1 0 1
0 1 0 1 2 0 1 1 2 2
Solution

#include <iostream> #include <string> using namespace std; string counter(string ip) { int i,count[10]; string res; //resultant string for(i=0;i<10;i++) count[i]=0; //setting all digits count to zero for(i=0;i<10;i++) count[((int)ip[i])-48]++; //incrementing the value of the digit's count. //creating the result string by appending the count of each digit to the ampty string res. for(i=0;i<10;i++) res += to_string(count[i])+" "; return res; //returning the result string } int main() { int n,i; cin>>n; //number of phone numbers string ip[n]; // array of phone numbers stored as a string. for(i=0;i<n;i++) //taking in each phone number cin>>ip[i]; for(i=0;i<n;i++) cout<<counter(ip[i])<<endl; //printing the result for //each digit in the phone number using the // counter function defined above. return 0; }
  • #1 Thieves
  • #2 The Queue of Doubts
  • #3 Summation of Primes
  • #4 Spacious Maximus
  • #5 Samosas
  • #6 Reasonably Sound
  • #7 Product of Digits
  • #8 Prime Usernames
  • #9 Path Shifter
  • #10 Keypad Count
  • #11 Even Vowels
  • #12 Encryption
  • #13 Decryption
  • #14 Canteen Accountant
  • #15 Attendance Register
  • #16 Amazing Year

Get in touch

  • executives@codingstudio.club
  • +91 9010342360
  • Vignana Bharthi Instute of Technology
    Aushapur, Ghatkesar, Hyderabad, Telengana - India

© coding.Studio();